<?php

namespace App\Repositories\Mgt;

use Prettus\Repository\Eloquent\BaseRepository as Repository;

class CategoryRepository extends Repository
{

    /**
     * 指定模型名称
     *
     * @return mixed
     */
    public function model()
    {
        return 'App\Models\Mgt\Category';
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $result = $this->model->parents()->with('children')->get();

        return $result;
    }


    public function children($id)
    {
        $parent = $this->model->findOrFail($id);

        return $parent->children()->get();
        //dd($parent->children()->get());
    }


    public function cats()
    {
        $result = $this->model->parents()->with('children')->get();

        return $result;
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }



    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
